@layout("/common/_container.html"){
<div class="row">
    <div class="col-sm-12">
        <div class="ibox float-e-margins">
            <div class="ibox-title">
                <h5>jqGrid列生成设置 - ${genQo.tableName!}</h5>
            </div>
            <div class="ibox-content">
                <div class="row row-lg">
                    <div class="col-sm-12">
                        <div class="row">
							<div>
								<!-- <#NameCon id="condition" name="名称" />
								</div>
								 -->
								<div class="col-sm-8">
	                            @if(shiro.hasPermission("/colModel/add")){
	                                <!-- <#button class='btn btn-info' name="新增" icon="fa-plus" clickFun="ColModel.openAddColModel()"/>  -->
	                            @}							
								</div>
								<div class="col-sm-4">						
			                        <div class="hidden-xs pull-right" id="ColModelTableToolbar" role="group">
		                                <#button class='btn btn-info' name="导出Excel" icon="fa-file-excel-o" clickFun="Export2Excel($('#ColModelGrid'))" space="true"/>
										<button type="button" aria-label="columns" class="btn btn-info" title="显示/显示过滤器" onclick="filterToolbar()">
											<i class="glyphicon glyphicon-search"></i><span>过滤记录</span>
										</button>		                                
										<button type="button" aria-label="columns" class="btn btn-info btn-outline dropdown-toggle" data-toggle="dropdown" title="隐藏显示列" onclick="columnSelector($('#ColModelGrid'))">
											<i class="glyphicon glyphicon-list"></i> <span class="caret"></span>
										</button>			                            
				                        <form action="${ctxPath}/colModel/Export2Excel" method="post" id="export2excel">
				                        	<input type="hidden" name="export2excel_params" id="export2excel_params">
				                        </form>
			                        </div>
		                        </div>
							</div>
                    	</div>
						<div class="row">
	                        <table id="ColModelGrid" />
	                        <div id="ColModelPager"></div>                        
						</div>
						<div class="row">
						    <div class="col-sm-6">
						        <button id="genBtn" type="button" class="btn btn-primary mr10"
						                onclick="generate()">
							         <span style="padding: 5px 20px;" id="genLabel">生成</span>
						        </button>
						    </div>
						</div>
		            </div>
		        </div>
	        </div>
	    </div>
	</div>
<script>
	$.jgrid.defaults.width = 780;
	$.jgrid.defaults.responsive = true;
	$.jgrid.defaults.styleUI = 'Bootstrap';
	//var data_url = "${ctxPath}/colModel/list2";
	var data_url = "${ctxPath}/colModel/list";
	var tablename = "${tablename}";

	$(document).ready(function () {
		if (tablename != ""){
			data_url = "${ctxPath}/colModel/listbytblname/${tablename}";	
		} else {
			$("#genBtn").hide();
		}
		
		$("#ColModelGrid").jqGrid({
			url: data_url,
			mtype: "GET",
			styleUI : 'Bootstrap',
			datatype: "json",
			colModel: [
	            @if(shiro.hasPermission("/colModel/update")||shiro.hasPermission("/colModel/delete")){
				{ label: '操作', name:'_act_', index:'', width:90, sortable:false, search: false, resizable: false, fixed:true},
				@}
				{ label: 'ID', name: 'id', index: 'id', key: true, hidden: true, search: true, resizable: true, fixed:true, sortable: true, align: 'right', sorttype: 'numeric', 
						searchoptions: {sopt: ['ge','gt','le','lt','ne']}},

				{ label: '列名', name: 'colName', index: 'colName', width: 100, search:true, resizable:true, fixed:true, align: 'left', sortable: true, sorttype: 'string', editable: false, },

				{ label: '类型', name: 'colSimpleType', index: 'colSimpleType', width: 100, search:true, resizable:true, fixed:true, align: 'left', sortable: true, sorttype: 'string', editable: false, },

				{ label: '标题', name: 'colLabel', index: 'colLabel', width: 100, search:true, resizable:true, fixed:true, align: 'left', sortable: true, sorttype: 'string', editable: true, },

				{ label: '键', name: 'key', index: 'isKey', width: 30, resizable:true, fixed:true, align: 'center', sortable: true, formatter: 'checkbox', editable: true, edittype: "checkbox", editoptions: { value: "1:0", defaultValue: "1" }},

				{ label: '生成', name: 'gen', index: 'isGen', width: 60, resizable:true, fixed:true, align: 'center', sortable: true, formatter: 'checkbox', editable: true, edittype: "checkbox", editoptions: { value: "1:0", defaultValue: "1" }},

				{ label: '隐', name: 'hidden', index: 'hidden', width: 30, resizable:true, fixed:true, align: 'center', sortable: true, formatter: 'checkbox', editable: true, edittype: "checkbox", editoptions: { value: "1:0", defaultValue: "1" },
					stype:'select', searchoptions:{sopt: ["eq"], value: "1:是;0:否"}},

				{ label: '列宽', name: 'width', index: 'width', width: 100, search:true, resizable:true, fixed:true, align: 'right', sortable: true, sorttype: 'numeric', editable: true, },

				{ label: '对齐', name: 'align', index: 'align', width: 100, search:true, resizable:true, fixed:true, align: 'left', sortable: true, sorttype: 'string', editable: true, formatter: 'select', edittype: "select", editoptions: { value: "left:←靠左;center:居中◎;right:靠右→"}},

				{ label: '可搜', name: 'search', index: 'search', width: 42, resizable:true, fixed:true, align: 'center', sortable: true, formatter: 'checkbox', editable: true, edittype: "checkbox", editoptions: { value: "1:0", defaultValue: "1" }},

				{ label: '列宽自适', name: 'resizable', index: 'resizable', width: 60, hidden: false,  resizable:true, fixed:true, align: 'center', sortable: true, formatter: 'checkbox', editable: true, edittype: "checkbox", editoptions: { value: "1:0", defaultValue: "1" }},

				{ label: '定宽', name: 'fixed', index: 'fixed', width: 42, hidden: false, resizable:true, fixed:true, align: 'center', sortable: true, formatter: 'checkbox', editable: true, edittype: "checkbox", editoptions: { value: "1:0", defaultValue: "1" }},

				{ label: '排序', name: 'sortable', index: 'sortable', width: 42, hidden: false, resizable:true, fixed:true, align: 'center', sortable: true, formatter: 'checkbox', editable: true, edittype: "checkbox", editoptions: { value: "1:0", defaultValue: "1" }},

				{ label: '搜索比较符', name: 'searchOptionsSopt', index: 'searchOptionsSopt', width: 120, search:true, resizable:true, fixed:true, align: 'left', sortable: true, sorttype: 'string', editable: true,
					formatter: "select", multiple: true, edittype: "select", editoptions: { multiple: true, value: '"eq":＝;"ne":≠;"lt":＜;"le":≤;"gt":＞;"ge":≥;"bw":字首;"bn":不以指定字符开头;"in":值在范围内;"ni":值不在范围内;"ew":字尾;"en":不以指定字符结尾;"cn":包含;"nc":不包含'}},

				{ label: '搜索参数', name: 'searchOptionsExtra', index: 'searchOptionsExtra', width: 100, hidden: true, search:true, resizable:true, fixed:true, align: 'left', sortable: true, sorttype: 'string', },

				{ label: '下拉?', name: 'fdSelect', index: 'fdSelect', width: 50, hidden: false, resizable:true, fixed:true, align: 'center', sortable: true, formatter: 'checkbox', editable: true, edittype: "checkbox", editoptions: { value: "1:0", defaultValue: "0" }},

				{ label: '多选?', name: 'multiple', index: 'multiple', width: 50, hidden: false, resizable:true, fixed:true, align: 'center', sortable: true, formatter: 'checkbox', editable: true, edittype: "checkbox", editoptions: { value: "1:0", defaultValue: "0" }},

				{ label: '格式', name: 'formatter', index: 'formatter', width: 100, hidden: false, search:true, resizable:true, fixed:true, align: 'left', sortable: true, sorttype: 'string', editable: false, },

				{ label: '原值格式', name: 'unformat', index: 'unformat', width: 100, hidden: true, search:true, resizable:true, fixed:true, align: 'left', sortable: true, sorttype: 'string', },

				{ label: '关联表', name: 'refTable', index: 'refTable', width: 100, hidden: true, search:true, resizable:true, fixed:true, align: 'left', sortable: true, sorttype: 'string', },

				{ label: '值字段', name: 'refKeyField', index: 'refKeyField', width: 100, hidden: true, search:true, resizable:true, fixed:true, align: 'left', sortable: true, sorttype: 'string', },

				{ label: '关联说明字段', name: 'refDescField', index: 'refDescField', width: 100, hidden: true, search:true, resizable:true, fixed:true, align: 'left', sortable: true, sorttype: 'string', },

				{ label: '关联过滤条件', name: 'refFilter', index: 'refFilter', width: 100, hidden: true, search:true, resizable:true, fixed:true, align: 'left', sortable: true, sorttype: 'string', },

				{ label: '搜索列表数据源url', name: 'sDataurl', index: 'sDataurl', width: 100, hidden: true, search:true, resizable:true, fixed:true, align: 'left', sortable: true, sorttype: 'string', },

				{ label: '编辑列表数据源url', name: 'eDataurl', index: 'eDataurl', width: 100, hidden: true, search:true, resizable:true, fixed:true, align: 'left', sortable: true, sorttype: 'string', },

				{ label: '可编辑', name: 'editable', index: 'editable', width: 60, hidden: false, resizable:true, fixed:true, align: 'center', sortable: true, formatter: 'checkbox', editable: true, edittype: "checkbox", editoptions: { value: "1:0", defaultValue: "1" }},

				{ label: '编辑参数', name: 'editOptionsExtra', index: 'editOptionsExtra', width: 100, hidden: true, search:true, resizable:true, fixed:true, align: 'left', sortable: true, sorttype: 'string', edittype: "checkbox", editoptions: { value: "1:0", defaultValue: "1" }},

				{ label: '生成列表值', name: 'genRefVar', index: 'genRefVar', width: 90, hidden: true, resizable:true, fixed:true, align: 'center', sortable: true, formatter: 'checkbox', edittype: "checkbox", editoptions: { value: "1:0", defaultValue: "1" }},

				{ label: '排序号', name: 'sortNum', index: 'sortNum', width: 60, search:true, resizable:true, fixed:true, align: 'right', sortable: true, sorttype: 'numeric', editable: true, },

				{ label: '创建时间', name: 'created', index: 'created', width: 100, hidden: true, search:true, resizable:true, fixed:true, align: 'center', sortable: true, sorttype: 'date', 
						searchoptions:{sopt: ["eq","ge","le","ne"], dataInit:datePick, attr:{title:'选择日期'}}},
				{ label: '修改时间', name: 'modified', index: 'modified', width: 100, hidden: true, search:true, resizable:true, fixed:true, align: 'center', sortable: true, sorttype: 'date', 
						searchoptions:{sopt: ["eq","ge","le","ne"], dataInit:datePick, attr:{title:'选择日期'}}},
			],
			cmTemplate: {autoResizable:false},
			footerrow: false,
			viewrecords: true,
			autowidth : true,
			height: 'auto',
			pager: "#ColModelPager",
			rowList: [10, 20, 50],
			rowNum: 10,
			rownumbers: true,
			loadonce: false,
			caption: "jqGrid列生成设置 ",
			multiselect: false,
			storeNavOptions: false,
			navOptions: {	
				reloadGridOptions: { fromServer: true }, 
			},
			gridComplete : function() {
				var ids = $("#ColModelGrid").jqGrid('getDataIDs');
				for (var i = 0; i < ids.length; i++) {
					var rowId = ids[i];
					var rowData = $('#ColModelGrid').jqGrid('getRowData',rowId);
					var info=''; be=''; ca='';
					info = "<button class='btn btn-info btn-xs' title='查看'  onclick=\"ColModel.openColModelView('" + rowData.id + "');\"><i class='fa fa-info-circle'></i></button>&nbsp";
		            @if(shiro.hasPermission("/colModel/update")){
					be = "<button class='btn btn-primary btn-xs' title='编辑'  onclick=\"ColModel.openColModelDetail('" + rowData.id + "');\"><i class='fa fa-pencil'></i></button>&nbsp";
					@}
		            @if(shiro.hasPermission("/colModel/delete")){
					ca = "<button class='btn btn-danger btn-xs' title='删除'  onclick=\"ColModel.delete('" + rowData.id + "');\"><i class='fa fa-times'></i></button>";
					@}
					jQuery("#ColModelGrid").jqGrid('setRowData', ids[i], {
						_act_ :  info + be + ca 
					});
				};
				$("#gview_ColModelGrid > .ui-jqgrid-titlebar").hide(); 	//隐藏caption
				//$('#gsh_ColModelGrid__act_')[0].html('<div class="btn btn-info btn-sm" icon="fa-search" onclick="$(\'#ColModelGrid\').jqGrid().searchGrid()">查询条件:</div>');
				filterToolbar();	//隐藏过滤器
				loadColState($("#ColModelGrid"));
			},
			ondblClickRow:function(row){
				//var rowData = $('#ColModelGrid').jqGrid('getRowData',row);
				//ColModel.openColModelView(rowData.id);
			},
	        resizeStop: function () {
				saveColState($("#ColModelGrid"));
	        },
	        onSelectRow: editRow,
	        editurl: "${ctxPath}/colModel/update",
	    })
	    .navGrid('#ColModelPager', {edit:false,
	    	add:false,
	    	del:false,
	    	search:true,
	    	refresh:true
	    })
		.searchGrid({multipleSearch:true, sopt: ['cn','eq','ne','le','ge'], showQuery: false}); //定义查询可用的操作符(全局)
		
		$("#searchmodfbox_ColModelGrid").find(".ui-jqdialog-titlebar-close").click();//初始化时关闭多条件查询
		//激活头部过滤条件                stringResult: true,
		$('#ColModelGrid').jqGrid('filterToolbar',{defaultSearch:'cn',stringResult: true,searchOnEnter : true, searchOperators: true});
		
		
		
		$(function(){
			$(window).resize(function(){   
				loadColState($("#ColModelGrid"));
			}); 
		});
		
        var lastSelection;

		function editRow(id) {
		    if (id && id !== lastSelection) {
		        var grid = $("#ColModelGrid");
		        //grid.jqGrid('restoreRow',lastSelection);
		        grid.jqGrid('saveRow',lastSelection);
		        grid.jqGrid('editRow',id, {keys:true, focusField: 4});
		        lastSelection = id;
		    }
		}		
	});
	/**
	 * 点击生成
	*/
	function generate() {
	    var baseAjax = Feng.baseAjax("/code/generatejqgrid", "生成jqGrid代码");
	    baseAjax.start();
	};		
</script>
<script src="${ctxPath}/static/modular/system/colModel/colModel.js"></script>
@}

